<%@ page language="java" import="java.util.*,com.ruohi.util.common.*,java.sql.*,com.ruohi.util.dbutil.*,org.json.JSONObject" pageEncoding="UTF-8"%><%
	boolean loginIpAuth = true; //是否开启登录ip限制
	Map setMap = CommonApplication.getEnumChildren("199", application);
	if(CommonString.getFormatInt(setMap.get("199001")) == 1){
		loginIpAuth = true;
	}else{
		loginIpAuth = false;
	}
	String rs = "fail";
	JSONObject oauthObj = null;
	if(loginIpAuth){
		String clientIp = Common.getIp(request);
		Map paras = new HashMap();
		//paras.put("ip", clientIp);
		paras.put("ip", "119.180.98.134");
		//String oauth = CommonString.getFormatPara(Common.doPost("http://service.21-sun.com/http/web21sun/form_ip_for_backend_login.jsp", paras));
		//oauthObj = new JSONObject(oauth);
	}else{
		oauthObj = new JSONObject();
		oauthObj.put("rs", "exist");
	}
	if(CommonString.getFormatPara(oauthObj.get("rs")).equals("exist")){
		Connection conn = null;
		String usern = CommonString.getFormatPara(request.getParameter("usern"));
		DBHelper dbHelper = DBHelper.getInstance();
		String password = CommonEncrypt.MD5(CommonString.getFormatPara(request.getParameter("password")));
		try{
			conn = dbHelper.getConnection();
			Map adminInfo = dbHelper.getMap(" select * from service_common_user where usern = ? and password = ? ", new Object[] { usern, password }, conn);
			if (null != adminInfo) {
				if (adminInfo.get("state").equals(0)) {
					rs = "state0";
				} else {
					session.setAttribute("adminInfo", adminInfo);
					//修改最后登录信息
					String sql = " UPDATE service_common_user SET login_count = isnull(login_count,0)+1 , last_login_date = '" + CommonDate.getToday("yyyy-MM-dd HH:mm:ss")
							+ "' , last_login_ip = '" + Common.getIp(request) + "' ";
					sql += " WHERE id = ? ";
					dbHelper.execute(sql, new Object[] { adminInfo.get("id") }, conn);
					rs = "ok";
				}
			}
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			DBHelper.freeConnection(conn);
		}
	}
	out.print(rs);
%>